package com.a2j.web.car.controller;

import com.a2j.beans.base.BaseBean;
import com.a2j.beans.base.code.ResponseCode;
import com.a2j.beans.car.CarBrand;
import com.a2j.web.car.service.CarBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author: bzb
 * Data: 2021/10/30 22:23
 * Desc: 车品牌
 */
@RestController
@RequestMapping ("carBrand")
@Api(tags = "车品牌")
public class CarBrandController {

    @Resource
    CarBrandService service;

    /**
     * 添加车品牌
     * @param carBrand 车品牌参数
     */
    @PostMapping("addCarBrand")
    @ApiOperation(value = "添加车品牌")
    @ApiImplicitParams({})
    public BaseBean<String> addCarBrand(@RequestBody CarBrand carBrand) {
        service.addCarBrand(carBrand);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 获取全部车品牌
     */
    @GetMapping("getAllCarBrands")
    @ApiOperation(value = "查询全部品牌列表")
    public BaseBean<List<CarBrand>> getAllCarBrands() {
        return service.getAllCarBrands();
    }

    /**
     * 获取全部车品牌的首字母列表
     */
    @GetMapping("getAllLetters")
    @ApiOperation(value = "查询全部品牌首字母列表")
    public BaseBean<List<String>> getAllLetters() {
        return service.getAllLetters();
    }

    /**
     * 获取车品牌详情
     * @param id 品牌id
     */
    @GetMapping("getCarBrandDetail/{id}")
    @ApiOperation(value = "查询品牌详情")
    @ApiImplicitParam(name = "id", value = "品牌id", dataType = "int", required = true, defaultValue = "1")
    public BaseBean<CarBrand> getCarBrandDetail(@PathVariable  Integer id) {
        return service.getCarBrandDetail(id);
    }

    /**
     * 删除车品牌
     * @param id 品牌id
     */
    @DeleteMapping("deleteCarBrand/{id}")
    @ApiOperation(value = "删除车品牌")
    @ApiImplicitParam(name = "id", value = "品牌id", dataType = "int", required = true, defaultValue = "1")
    public BaseBean<String> deleteCarBrand(@PathVariable Integer id) {
        service.deleteCarBrand(id);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 更新车品牌信息
     * @param carBrand 品牌属性
     */
    @PutMapping("updateCarBrand")
    @ApiOperation(value = "更新品牌信息")
    @ApiImplicitParams({})
    public BaseBean<String> updateCarBrand(@RequestBody CarBrand carBrand) {
        service.updateCarBrand(carBrand);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 车品牌开关
     * @param id 品牌id
     * @param enable 开关状态  0:关 1:开
     */
    @PutMapping("enable")
    @ApiOperation(value = "品牌开关")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "品牌id", dataType = "int", required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "enable", value = "开关状态  0:关 1:开", dataType = "int", defaultValue = "0")
    })
    public BaseBean<String> enable(@RequestParam Integer id, @RequestParam Integer enable) {
        service.enable(id, enable);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

}
